package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.LoginDto;
import com.zzyl.mapper.EmployeeMapper;
import com.zzyl.service.EmployeeService;
import com.zzyl.utils.JwtUtil;
import com.zzyl.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description EmployeeServiceImpl
 * @Author liangDong
 * @Date 2025-05-12  9:44
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public UserVo login(LoginDto loginDto) {
        UserVo userVo = employeeMapper.login(loginDto);

        if (userVo != null) {
            Map<String,Object> dataMap = new HashMap<>();
            dataMap.put("id", userVo.getId());
            dataMap.put("username", userVo.getUsername());
            dataMap.put("realName", userVo.getRealName());
            dataMap.put("email", userVo.getEmail());
            dataMap.put("deptName", userVo.getDeptNo());
            dataMap.put("postName", userVo.getPostNo());
            dataMap.put("mobile", userVo.getMobile());
            dataMap.put("sex", userVo.getSex());

            String jwt = JwtUtil.createJWT("$2a$10$PVtHnkj86mJgf6li/yron.LRx/cQAlaiZkBJ9BeogCNTryXJRT1YC",12,dataMap);
            userVo.setUserToken(jwt);
            return userVo;
        }

        return null;
    }
}
